// JavaScript Document
(function(window){
	
	function Lyric(path){
		return new Lyric.prototype.init(path);

		}
		Lyric.prototype={
			construstor:Lyric,
		
	  init:function(path){
		  
		  this.path= path;
		  
		  },
		  times:[],
		  lyrics:[],
		  
		  //初始化歌词
		  downLyric:function(callBack){
			 var  $this=this;
			  $.ajax({
			url:$this.path,	
			dataType:"text",

			success:function(data){
				$this.analysis(data);
			    callBack();

			},
			error:function(e){
				
				consloe.log(e)
				
					
			     }

		  })
		},
		//歌词解析
		analysis:function(data){
			$this=this;
			$this.times=[]
			$this.lyrics=[]
			var arry=data.split("\n");
			//正则表达式
			var timeReg=/\[(\d*:\d*\.\d*)\]/
			$.each(arry,function(index,ele){
				//初始化歌词
				var lys=ele.split("]")[1];
				/*console.log(lys)*/
				if(lys.length==1) return true;
				$this.lyrics.push(lys);
				var res = timeReg.exec(ele);
			/*	console.log(res)*/
				if(res==null) return true;
				var timestr=res[1];
				var res1=timestr.split(":");
				var minu = parseInt(res1[0]*60);
				var sec = parseFloat(res1[1]);
				var time =Number(Number(minu+sec).toFixed(2));
				$this.times.push(time);
				
				});
			},
			//歌词同步
			index:-1,
		  lyricCurrentTime:function(currentTime){
			  if(currentTime>=this.times[0]){
				  this.index++;
				  this.times.shift();
				  }
			  return this.index;
			  }
		}
		
		Lyric.prototype.init.prototype = Lyric.prototype;
		window.Lyric = Lyric;
	}(window))